<?php

class CommentAutoAttr extends CActiveRecordBehavior{
	public $type = array(
		1 => 'Travel',
		2 => 'Hotel',
		3 => 'Scenic',
		4 => 'Native',
		5 => 'Ticket',
	);	
	public function beforeValidate($event) {
		$owner = $this->getOwner();
		$worker =Yii::app()->adminUser->worker;
		if ($owner->parent_id) {
			$owner->target_object_type = CHtml::value($owner, 'parent.target_object_type');
			$owner->target_object_id = CHtml::value($owner, 'parent.target_object_id');
		} else  {
			if($owner->target_object_id && empty($owner->target_object_type)) {
				$goods = Goods::model()->findByPk($owner->target_object_id);
				if (is_object($goods)) {
					$owner->target_object_type = $this->type[$goods->class_id];
				}
			}
		}
		$owner->uid = $worker->id;
		$owner->nickname = CHtml::value($worker, 'profile.nickname');
	}

}

?>